from pydantic import BaseModel, Field, EmailStr
from typing import Optional


class UserBase(BaseModel):
    """基础模型，包含公共字段"""

    uname: str = Field(..., max_length=100, description="用户名")
    nickname: str = Field(..., max_length=50, description="昵称")
    phone: Optional[str] = Field(None, max_length=20, description="用户的手机号")

    class Config:
        orm_mode = True


class UserCreate(UserBase):
    """用于创建用户的模型"""

    pwd: str = Field(..., max_length=64, description="密码")
    role: int = Field(1, description="角色：0-管理员 1-普通用户")
    openid: Optional[str] = Field(None, max_length=100, description="用户的微信OpenID")
    headimgurl: Optional[str] = Field(None, max_length=255, description="头像URL")


class UserOut(UserBase):
    """用于返回用户信息的模型"""

    id: int = Field(..., description="用户ID")
    is_active: int = Field(0, description="用户状态：0-禁用 1-启用")

    class Config:
        schema_extra = {
            "example": {
                "id": 1,
                "uname": "testuser",
                "nickname": "测试用户",
                "role": 1,
                "phone": "13800138000",
                "headimgurl": "https://example.com/avatar.jpg",
                "is_active": 1,
            }
        }
